<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Frees extends FOX_Controller {

	function __construct ()
	{
		parent::__construct();
		$this->load->model('category_m');
		$this->load->model('api_good_m');
		$this->load->model('member_m');
		$this->load->model('good_m');
		$this->load->model('shop_m');
		$this->load->model('areas_m');
		$this->load->model('attachs_m');
		if(!$this->session->userdata('user_id')){
            redirect(site_url('nologin'));
        }
	}
	public function index(){
		// $web_category = $this->uri->segment(3);
		$data['categorys'] = $this->category_m->get_cates_by_all_category(1);
		//good_voucher = 1免单
		$data['total_rows'] = $this->api_good_m->get_goods_free_count(1);
		$data['goods'] = $this->api_good_m->get_vouchers_goods_list(0,$this->config->item('page_list_voucher'),1,1,'desc');
		if($data['goods']){
			foreach($data['goods'] as $k => $v){
				$data['goods'][$k]['count_orders'] = $this->api_good_m->count_shop_orders_count_by_good_id($v['good_id']);
				//获取图片
				$pic_lists = $this->attachs_m->get_one_attachs_by($v['good_cover']);
				if($pic_lists){
					$data['goods'][$k]['good_cover'] = get_jianlou_image($pic_lists['file_location'],$pic_lists['file_name'],"big");
				}else{
					$data['goods'][$k]['good_cover'] = base_url('uploads/goods/nopic.jpg');
				}
			}
		}
		// pp($data);exit;
		$this->load->view('frees_list',$data);
	}
}
